1
|
|
|
/** |
2
|
|
|
* File containing the SimpleBatchUpload class |
3
|
|
|
* |
4
|
|
|
* @copyright (C) 2016, Stephan Gambke |
5
|
|
|
* @license GNU General Public License, version 2 (or any later version) |
6
|
|
|
* |
7
|
|
|
* This software is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (at your option) any later version. |
11
|
|
|
* This software is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
* |
18
|
|
|
* @file |
19
|
|
|
* @ingroup SimpleBatchUpload |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** global: mediaWiki */ |
23
|
|
|
/** global: jQuery */ |
24
|
|
|
|
25
|
|
|
/* Load the RL module mediawiki.api.messages and when loaded and the page is ready; */ |
26
|
|
|
$.when( mw.loader.using(["mediawiki.api.messages", "mediawiki.jqueryMsg"]), $.ready ).done( function() { |
|
|
|
|
27
|
|
|
/* Load the messages that you need if they are not yet loaded, then do stuff with them */ |
28
|
|
|
new mw.Api().loadMessagesIfMissing( ['simplebatchupload-comment' ] ).done( |
|
|
|
|
29
|
|
|
function ( $, mw, undefined ) { |
30
|
|
|
|
31
|
|
|
'use strict'; |
32
|
|
|
|
33
|
|
|
$( function () { |
34
|
|
|
$( '#fileupload' ) |
35
|
|
|
|
36
|
|
|
.on( 'change', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
37
|
|
|
.on( 'drop', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
38
|
|
|
|
39
|
|
|
.fileupload( { |
40
|
|
|
dataType: 'json', |
41
|
|
|
dropZone: $( '#fileupload-dropzone' ), |
42
|
|
|
progressInterval: 100, |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
add: function ( e, data ) { |
46
|
|
|
|
47
|
|
|
data.id = Date.now(); |
48
|
|
|
|
49
|
|
|
var status = $('<li>') |
50
|
|
|
.attr( 'id', data.id ) |
51
|
|
|
.text( data.files[0].name ); |
52
|
|
|
|
53
|
|
|
$( '#fileupload-results' ).append( status ); |
54
|
|
|
|
55
|
|
|
data.formData = { |
56
|
|
|
format: 'json', |
57
|
|
|
action: 'upload', |
58
|
|
|
token: $( this ).fileupload( 'option', 'token' ), |
59
|
|
|
comment: mw.message( 'simplebatchupload-comment' ), |
60
|
|
|
ignorewarnings: 1, |
61
|
|
|
filename: data.files[ 0 ].name |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
data.submit() |
65
|
|
|
.success( function ( result /*, textStatus, jqXHR */ ) { |
66
|
|
|
|
67
|
|
|
if ( result.error !== undefined ) { |
68
|
|
|
|
69
|
|
|
status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
70
|
|
|
|
71
|
|
|
} else { |
72
|
|
|
var link = $( '<a>' ); |
73
|
|
|
link |
74
|
|
|
.attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
75
|
|
|
.text( result.upload.filename ); |
76
|
|
|
|
77
|
|
|
status |
78
|
|
|
.addClass( 'ful-success' ) |
79
|
|
|
.text( ' OK' ) |
80
|
|
|
.prepend( link ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} ) |
84
|
|
|
.error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
85
|
|
|
status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
86
|
|
|
} ); |
87
|
|
|
|
88
|
|
|
}, |
89
|
|
|
|
90
|
|
|
progress: function (e, data) { |
91
|
|
|
if ( data.loaded !== data.total ) { |
92
|
|
|
$( '#' + data.id ) |
93
|
|
|
.text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' ); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} ); |
97
|
|
|
|
98
|
|
|
$( document ).bind( 'drop dragover', function ( e ) { |
99
|
|
|
e.preventDefault(); |
100
|
|
|
} ); |
101
|
|
|
} ); |
102
|
|
|
|
103
|
|
|
}( jQuery, mediaWiki ));} ); |
104
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.